Rewriting Your Git History, Removing Files Permanently [Cheat Sheet Included]

rw-book-cover

Metadata

Highlights

  • This is where the --all flag comes in. This flag tells git to grab every branch from the remote repository. And the --tags flag tells git to grab every tag as well. So this command tells git to download the entire repository history, a complete and total clone. (View Highlight)
  • git reset —hard HEAD~1 (View Highlight)
  • Normally, this command by itself tells git to unstage anything we’ve added with git add, but haven’t committed yet. (View Highlight)
    • Note: git reset
  • HEAD is what git calls the most recent commit on the checked out branch. (View Highlight)
  • HEAD~1 means “the first commit prior to the most recent” (likewise HEAD~2 means “two commits prior to the most recent”). (View Highlight)
  • Finally, the --hard tells git to throw away any differences between the current state and the state we’re resetting to (View Highlight)
  • We all know git commit, but the --amend flag is our friend here. This tells git that we want to edit the previous commit, rather than creating a new one (View Highlight)
    • Note: git —amend